<template>
  <div>
    <el-col :span="9" class="propertyborder-title" :title="content">
      {{ title }}
    </el-col>
    <el-col :span="15" class="propertyborder-content">
      <el-button
        type="button"
        size="mini"
        @click="addbutton"
        style="padding-top:5px;padding-bottom:5px;"
      >
        <i class="fa fa-plus"></i>&nbsp;添加子项
      </el-button>
    </el-col>
    <el-col :span="24" class="widget-config-container">
      <template>
        <draggable
          tag="ul"
          :list="datalist"
          v-bind="{
            group: { name: 'options1' },
            ghostClass: 'ghost',
            handle: '.drag-item',
          }"
          handle=".drag-item"
        >
          <li style="background: lightgray;padding: 2px;margin-bottom:2px;">
            <div style="display:inline-block;width:60%;padding-left:10px;">
              <label style="width:65px;float:left">选项名称</label>
            </div>
            <label>操作</label>
          </li>
          <li
            v-for="(item, index) in datalist"
            :key="index"
            style="background: lightgray;padding: 2px;margin-bottom:2px;"
          >
            <!-- <el-input placeholder="栅格值" size="mini" style="width: 100px;" type="number" v-model.number="item.span"></el-input> -->
            <div style="display:inline-block;width:60%;padding-left:10px;">
              <input v-model="item.title" style="width:100px;float:left" />
            </div>
            <el-button
              @click="layerPlaneshowDialog(index)"
              circle
              plain
              type="danger"
              size="mini"
              icon="el-icon-edit"
              style="padding: 4px;margin-left: 5px;"
            ></el-button>
            <el-button
              @click="handleButtonRemove(index)"
              circle
              plain
              type="danger"
              size="mini"
              icon="el-icon-minus"
              style="padding: 4px;margin-left: 5px;"
            ></el-button>
            <i
              class="drag-item fa fa-bars"
              style="font-size: 16px;margin: 0 5px;cursor: move;"
            ></i>
          </li>
        </draggable>
      </template>
    </el-col>
  </div>
</template>
<script>
import draggable from 'vuedraggable';
import store from '@/store';
import { layoutComponents } from '../../config/controlconfig.js';
import configs from '@/configs/index.js';
export default {
  props: ['title', 'content', 'datalist'],
  data() {
    return { tempctrl: null };
  },
  components: { draggable },
  methods: {
    addbutton() {
      this.tempctrl = null;
      if (
        this.$store.state.formdesignconfig.selectWidget !== null &&
        this.$store.state.formdesignconfig.selectWidget.type !== undefined
      ) {
        console.log(JSON.stringify(layoutComponents));
        const result = kylinjson.kylinjson({
          path:
            "$.[?(@.type=='" +
            this.$store.state.formdesignconfig.selectWidget.type +
            "')]",
          json: layoutComponents,
          key: configs.keycode,
        });
        this.tempctrl = result[0].options.planelist[0];
      }
      if (this.tempctrl !== null) {
        const index = this.datalist.length + 1;
        let panel = JSON.parse(JSON.stringify(this.tempctrl));
        panel.model =
          'cel' +
          Date.parse(new Date()) / 1000 +
          '' +
          Math.ceil(Math.random() * 99999);
        panel.title = '模块' + index;
        this.datalist.push(panel);
      }
    },
    handleButtonRemove(index) {
      this.datalist.splice(index, 1);
    },
    layerPlaneshowDialog(index) {
      store.commit('setselectWidget', this.datalist[index]);
      // this.setSelectWidget(this.datalist[index])
    },
  },
};
</script>
<style scoped lang="less">
.propertyborder-title {
  padding-right: 3px;
  padding-left: 3px;
  padding-top: 4px;
  padding-bottom: 4px;
  border-top: none;
  border-right: none;
  line-height: 28px;
  min-height: 28px;
}

.propertyborder-content {
  border-top: none;
  border-right: none;
  padding-right: 3px;
  padding-left: 3px;
  padding-top: 4px;
  padding-bottom: 4px;
  line-height: 28px;
  min-height: 28px;
  text-align: right;
}
.widget-config-container {
  position: relative;
  max-height: 210px;
  overflow-y: auto;
  overflow-x: hidden;
  .el-header {
    border-bottom: solid 2px #e4e7ed;
    padding: 0px;
  }

  .column-setting .el-form-item__label {
    float: none;
    display: inline-block;
    text-align: left;
    padding: 0 0 2px;
  }

  .config-content {
    border-left: solid 1px #e6e6e6;

    .el-form-item__label {
      padding: 0;
      font-weight: 500;
      float: none;
    }

    .el-form-item {
      /*border-bottom: solid 1px #e1e1e1;
            margin-bottom: 0px;*/
      margin: 5px;
    }
  }

  .ghost {
    background: #fff;
    border: 1px dashed #409eff;

    &::after {
      background: #fff;
      display: block;
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
    }
  }

  ul {
    margin: 0;
    padding: 0;
  }

  li.ghost {
    list-style: none;
    font-size: 0;
    display: block;
    position: relative;
  }
}
</style>
